package com.example.parktime;


import java.util.Calendar;
import java.util.Date;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;

import com.example.parktime.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends Activity {
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    
	private String horaInicial;
	private String horaFinal;
	private String valorHoraIncial;
	private String ValorHorasExtras;
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    public void Hora(View view){

    	Calendar calendario = Calendar.getInstance();
		
    	 EditText valorInicial =(EditText)findViewById(R.id.editText1);
    	 valorHoraIncial=valorInicial.getText().toString();
    	 
    	
    	 
    	 EditText valorDemais =(EditText)findViewById(R.id.editText2);
    	 ValorHorasExtras=valorDemais.getText().toString();
    	 
    	 
    	SimpleDateFormat dateFormat_hora = new SimpleDateFormat("HH:mm:ss");
    	TextView hora = (TextView) findViewById(R.id.textView4);
    	String hora_atual = dateFormat_hora.format(calendario.getTime());
    	horaInicial=(String.valueOf(calendario.getTimeInMillis()));
    	hora.setText(String.valueOf(hora_atual) );
    	
         
    }
    
    public void Pagar(View view){
    	Calendar calendario = Calendar.getInstance();
    	horaFinal=(String.valueOf(calendario.getTimeInMillis()));
    	SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    	TextView Final = (TextView) findViewById(R.id.textView6);
    	String hora_final = dateFormat.format(calendario.getTime());
    	Final.setText(String.valueOf(hora_final));
    
    	double tempo = ((((Double.parseDouble(horaFinal)-Double.parseDouble(horaInicial))/1000))/60)/60;
    	
    	double valor= (Double.parseDouble(valorHoraIncial) + (tempo * Double.parseDouble(ValorHorasExtras)));
    	
    	TextView resultado = (TextView) findViewById(R.id.textView8);
    	
    	NumberFormat formato = NumberFormat.getCurrencyInstance();
    	resultado.setText(String.valueOf(formato.format(valor)));
    	
    	
    	
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
